package com.zqh.myfmmall.constants;

import java.util.concurrent.TimeUnit;

/**
 * @Description :
 * @Author :kono淇杭哒、
 * @Create 2022-02-05 21:32
 */
public enum RedisExpireTime{
    //商品类型的缓存数据过期时间
    PRODUCT(30 * 60,TimeUnit.SECONDS),
    //分类类型的缓存数据过期时间
    CATEGORY(120 * 60,TimeUnit.SECONDS),
    //评价
    COMMENTS(10,TimeUnit.SECONDS),
    //轮播图缓存数据过期时间
    INDEXPICTURE(60 * 60 * 24,TimeUnit.SECONDS);

    private Integer time;
    private TimeUnit timeUnit;
    private RedisExpireTime(Integer time,TimeUnit timeUnit){
        this.time = time;
        this.timeUnit = timeUnit;
    }

    public Integer getTime(){
        //对每个分类的过期时间随机增加3到8分钟，用于稀释集中过期的key，解决缓存雪崩问题
        return this.time + 3  + (int)(Math.random() * 5);
    }

    public TimeUnit getTimeUnit(){
        return this.timeUnit;
    }
}
